package com.js.rtu.greendao.dao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.js.rtu.greendao.db.HistoryBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "HISTORY_BEAN".
*/
public class HistoryBeanDao extends AbstractDao<HistoryBean, Long> {

    public static final String TABLENAME = "HISTORY_BEAN";

    /**
     * Properties of entity HistoryBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Time = new Property(0, Long.class, "time", false, "TIME");
        public final static Property Id = new Property(1, Long.class, "id", true, "_id");
        public final static Property StartTime = new Property(2, String.class, "startTime", false, "START_TIME");
        public final static Property EndTime = new Property(3, String.class, "endTime", false, "END_TIME");
        public final static Property IsSuccess = new Property(4, boolean.class, "isSuccess", false, "IS_SUCCESS");
        public final static Property Pos = new Property(5, int.class, "pos", false, "POS");
        public final static Property Data = new Property(6, String.class, "data", false, "DATA");
    }

    private Query<HistoryBean> historyInfoBean_MHistoryBeanListQuery;

    public HistoryBeanDao(DaoConfig config) {
        super(config);
    }
    
    public HistoryBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"HISTORY_BEAN\" (" + //
                "\"TIME\" INTEGER," + // 0: time
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 1: id
                "\"START_TIME\" TEXT," + // 2: startTime
                "\"END_TIME\" TEXT," + // 3: endTime
                "\"IS_SUCCESS\" INTEGER NOT NULL ," + // 4: isSuccess
                "\"POS\" INTEGER NOT NULL ," + // 5: pos
                "\"DATA\" TEXT);"); // 6: data
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"HISTORY_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, HistoryBean entity) {
        stmt.clearBindings();
 
        Long time = entity.getTime();
        if (time != null) {
            stmt.bindLong(1, time);
        }
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(2, id);
        }
 
        String startTime = entity.getStartTime();
        if (startTime != null) {
            stmt.bindString(3, startTime);
        }
 
        String endTime = entity.getEndTime();
        if (endTime != null) {
            stmt.bindString(4, endTime);
        }
        stmt.bindLong(5, entity.getIsSuccess() ? 1L: 0L);
        stmt.bindLong(6, entity.getPos());
 
        String data = entity.getData();
        if (data != null) {
            stmt.bindString(7, data);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, HistoryBean entity) {
        stmt.clearBindings();
 
        Long time = entity.getTime();
        if (time != null) {
            stmt.bindLong(1, time);
        }
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(2, id);
        }
 
        String startTime = entity.getStartTime();
        if (startTime != null) {
            stmt.bindString(3, startTime);
        }
 
        String endTime = entity.getEndTime();
        if (endTime != null) {
            stmt.bindString(4, endTime);
        }
        stmt.bindLong(5, entity.getIsSuccess() ? 1L: 0L);
        stmt.bindLong(6, entity.getPos());
 
        String data = entity.getData();
        if (data != null) {
            stmt.bindString(7, data);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1);
    }    

    @Override
    public HistoryBean readEntity(Cursor cursor, int offset) {
        HistoryBean entity = new HistoryBean( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // time
            cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1), // id
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // startTime
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // endTime
            cursor.getShort(offset + 4) != 0, // isSuccess
            cursor.getInt(offset + 5), // pos
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6) // data
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, HistoryBean entity, int offset) {
        entity.setTime(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setId(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1));
        entity.setStartTime(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setEndTime(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setIsSuccess(cursor.getShort(offset + 4) != 0);
        entity.setPos(cursor.getInt(offset + 5));
        entity.setData(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(HistoryBean entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(HistoryBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(HistoryBean entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "mHistoryBeanList" to-many relationship of HistoryInfoBean. */
    public List<HistoryBean> _queryHistoryInfoBean_MHistoryBeanList(Long time) {
        synchronized (this) {
            if (historyInfoBean_MHistoryBeanListQuery == null) {
                QueryBuilder<HistoryBean> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.Time.eq(null));
                historyInfoBean_MHistoryBeanListQuery = queryBuilder.build();
            }
        }
        Query<HistoryBean> query = historyInfoBean_MHistoryBeanListQuery.forCurrentThread();
        query.setParameter(0, time);
        return query.list();
    }

}
